Go to Properties of the class library and make sure “XML Documentation file” checkbox is checked. Build the library and you can see an XML file in the bin folder.
How to add comments to a class library? Leave a comment
Remove Version Discloser in MVC applications Leave a comment
- To remove X-AspNetMvc-Version, add the below code in Application_Start of Global.asx
MvcHandler.DisableMvcResponseHeader = true;
2. To remove X-AspNet-Version and Server header, add the below method in Global.asax
protectedvoidApplication_PreSendRequestHeaders()
{
Response.Headers.Remove(“Server”);
Response.Headers.Remove(“X-AspNet-Version”);
}
3. To remove X-Powered-By header, add the below code under System.webServer in web.config file
<httpProtocol>
<customHeaders>
<remove name=”X-Powered-By” />
</customHeaders>
</httpProtocol>
How to enable CORS in MVC? Leave a comment
- Need to add Access-Control-Allow-Origin header value for each request that requires CORS support :
HttpContext.Response.AppendHeader(“Access-Control-Allow-Origin”, “*”);
2. Add this in the web.config file :
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name=”Access-Control-Allow-Origin” value=”*” />
</customHeaders>
</httpProtocol>
</system.webServer>
We can follow either of the way.
Issue : Azure cloud deployment fails : Certificate with thumbprint was not found Leave a comment
What worked for me was:
- Goto powershell and type mmc
- Add certificates snap-in by going to File > Add/Remove Snap-in > Choose Certificates from the list > Choose My user Account
- Right click on Certificates – Current User and select Find Certificates
- On the dialog box, set Contains to ‘azure’ and Look in Field to ‘Issued To’
- Press Find Now. You should be able to see a list of certificates.
- Check for the thumbprint by double-clicking the certificate > Details tab > scroll down to Thumbprint
- Once you found your certificate, close the dialog, Right click and select Export
- Select to export the private key. Follow the steps until you have a *pfx file for upload to Azure
- Goto your service and select the Certificates tab
- Click Upload, select the exported *pfx file, and supply the password you’ve set during export
- Goto Dashbord and update the Cloud package
- List item
Credits : StackOverflow
Issue : Error while publishing web role in VS 2013: There was an error reflecting type ‘Microsoft.Cct.AzureDiagnostics.ObjectModel.PublicConfig’ Leave a comment
- In your Azure project, edit any
diagnostics.wadcfgx
files in a text editor, and set<IsEnabled>false</IsEnabled>
(near the bottom) - Right click project > Publish, untick
Send diagnostics data to Application Insights
, hit Next
Credits : StackOverflow
Check if a property exists in a dynamic variable Leave a comment
using System.Linq.Expressions;
public bool IsPropertyExists(dynamic dynamicVariable,string propertyToCheck)
{
try
{
IDynamicMetaObjectProvider metaObjectProvider = dynamicVariable as IDynamicMetaObjectProvider;if (null == metaObjectProvider) throw new InvalidOperationException(
“The supplied object must be a dynamic object ” +
“(i.e. it must implement IDynamicMetaObjectProvider)”
);DynamicMetaObject dynamicMetaObject = metaObjectProvider.GetMetaObject(
Expression.Constant(metaObjectProvider)
);IEnumerable<string> propertyNames = dynamicMetaObject.GetDynamicMemberNames();
bool exist = propertyNames.Contains(propertyToCheck);
return exist;
}
catch (RuntimeBinderException)
{
return false;
}
}
Usage :
bool propExists = IsPropertyExists(dynamicVariable, “Prop1”);
How to insert a byte array into SQL Server varbinary column Leave a comment
This can be done using Parameterised Queries as below :
string command = “Insert into [dbo].[Students] (Sname,BinaryColumn) Values (‘raees’,@binaryData)”;
SqlCommand sqlCommand = new SqlCommand(command, con);
sqlCommand.Parameters.AddWithValue(“binaryData”, [binary data]);
sqlCommand.ExecuteNonQuery();
Get the ASP.NET MVC Version Installed In Your System Using Code During Runtime Leave a comment
string version = typeof(Controller).Assembly.GetName().Version.ToString();
Simple Custom Jquery Datepicker Validator 1 comment
Pulgin :
(function($){ var maxMonthValue = 12; var maxDayValue = 31; var noOfDaysInMonth = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var noOfDaysInMonthForLeapYear = [0,31,29,31,30,31,30,31,31,30,31,30,31]; function AddDatePickerErrorMessage(id) { $('#'+id+'Validator').html('Please enter valid date').css('color','red'); } function RemoveDatePickerErrorMessage(id) { $('#'+id+'Validator').empty(); } function ValidateDateValues(value,id,dpFormat) { var leapYear = false; var getNoOfDaysInPresentMonth = 0; var monthValue = 0; var dayValue = 0; var yearValue = 0; if(dpFormat == 'dd-mm-yy') { monthValue = value[1]; dayValue = value[0]; yearValue = value[2]; } else if(dpFormat == 'mm-dd-yy') { monthValue = value[0]; dayValue = value[1]; yearValue = value[2]; } if((monthValue == "" || monthValue == null || monthValue == undefined) ||(dayValue == "" || dayValue == null || dayValue == undefined) ||(yearValue == "" || yearValue == null || yearValue == undefined)) { AddDatePickerErrorMessage(id); } else { if((monthValue.length > 2 || dayValue.length > 2 || yearValue.length != 4) || (parseInt(monthValue) > maxMonthValue || parseInt(dayValue) > maxDayValue) || (parseInt(monthValue) == 0 || parseInt(dayValue) == 0 || parseInt(yearValue) == 0)) { AddDatePickerErrorMessage(id); } else { leapYear = LeapYearCheck(parseInt(yearValue)); if(parseInt(monthValue) == 2) { if(leapYear) { getNoOfDaysInPresentMonth = noOfDaysInMonthForLeapYear[parseInt(monthValue)]; } else { getNoOfDaysInPresentMonth = noOfDaysInMonth[parseInt(monthValue)]; } } else { getNoOfDaysInPresentMonth = noOfDaysInMonth[parseInt(monthValue)]; } if(parseInt(dayValue) > getNoOfDaysInPresentMonth) { AddDatePickerErrorMessage(id); } } } } function LeapYearCheck(year) { return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); } $.fn.validateDatePicker = function() { this.each(function(){ var $input = $(this)[0]; $($input).keyup(function(){ var dpId = $input.id; var dpFormat = $("#"+dpId).datepicker('option', 'dateFormat'); var dpValue = $input.value; var completeDate = dpValue.split("-"); if(dpValue != "") { if(completeDate.length == 3) { RemoveDatePickerErrorMessage(dpId); var monthInDate = 0; var dayInDate = 0; var yearInDate = 0; if(dpFormat == 'dd-mm-yy') { monthInDate = completeDate[1]; dayInDate = completeDate[0]; yearInDate = completeDate[2]; } else if(dpFormat == 'mm-dd-yy') { monthInDate = completeDate[0]; dayInDate = completeDate[1]; yearInDate = completeDate[2]; } var dateForValidation = [monthInDate,dayInDate,yearInDate]; ValidateDateValues(dateForValidation,dpId,dpFormat); } else { AddDatePickerErrorMessage(dpId); } } }) }) } })(jQuery);
Usage :
Html :
<input type="text" class="hasDatePicker" id="dp1" /> <div id="dp1Validator"><div>
Script :
$('.hasDatePicker').datepicker().validateDatePicker();
Enterprise Library 6, Semantic Logging, Part 4 advantages, customising Leave a comment
This post continues on from part 3:
Enterprise Library 6, Semantic Logging, Part 3, Getting into the details
In-process / out of process logging
Again, here’s the diagrams showing the difference between in-process and out-of-process logging. (Taken from the EL6 documentation)
As soon as performance in your logging is required, out-of-process should be used. If you use out-of-process though, deployment of your application is more complicated, 2 separate applications are then required for each target host. (SLAB OUT-OF-PROCESS service must run on the same host as the event sources)
Advantages compared to Enterprise Library Logging Block
- live configuration, trace tuning without restarting web apps in the IIS (by OUT-OF-PROCESS)
- high performance logging
- OUT-OF-PROCESS and distributed software systems support
- easy to configure in OUT-OF-PROCESS
- no unity dependency
- Complicated Logging configuration is no longer required and the web.config, app.config is almost free from EL configurations
- Application is free from listeners…
View original post 223 more words