Pass a user defined object to ASP.NET Webmethod from jQuery, using JSON

I quickly set up this project and I was able to successfully call my web method, please adjust your code accordingly. Make sure your class property names are the same as the ones that you pass through JavaScript. Webservice public static Contact getContact(Contact cnt) { = “Abijeet Patro”; = “Blah Blah”; return cnt; … Read more

How does Html.Raw MVC helper work?

Because encoded characters are HTML, and the Raw version of that string is the encoded one. Html.Raw renders what it is given without doing any html encoding, so with ViewBag.div = “<div> Hello </div>”;: @Html.Raw(ViewBag.div); Renders <div> Hello </div> However, when you have encoded characters in there, such as ViewBag.Something = “&gt;”; the raw version … Read more

What is a Generic Handler in and its use?

Generic handlers are the .NET components that implement the System.Web.IHttpHandler interface. Any class that implements the IHttpHandler interface can act as a target for the incoming HTTP requests. Page is also generic handler. In general generic handlers have an extension of ASHX. You can find example here

Response.Redirect which POSTs data to another URL in ASP.NET

you can send huge data also with this trick.. Response.Clear(); StringBuilder sb = new StringBuilder(); sb.Append(“<html>”); sb.AppendFormat(@”<body onload=’document.forms[“”form””].submit()’>”); sb.AppendFormat(“<form name=”form” action='{0}’ method=’post’>”,postbackUrl); sb.AppendFormat(“<input type=”hidden” name=”id” value=”{0}”>”, id); // Other params go here sb.Append(“</form>”); sb.Append(“</body>”); sb.Append(“</html>”); Response.Write(sb.ToString()); Response.End();

How do I install and use the ASP.NET AJAX Control Toolkit in my .NET 3.5 web applications?

Install the ASP.NET AJAX Control Toolkit Download the ZIP file from the ASP.NET AJAX Control Toolkit Releases page of the CodePlex web site. Copy the contents of this zip file directly into the bin directory of your web site. Update web.config Put this in your web.config under the <controls> section: <?xml version=”1.0″?> <configuration> … … Read more

Change Single URL query string value

You can’t modify the QueryString directly as it is readonly. You will need to get the values, modify them, then put them back together. Try this: var nameValues = HttpUtility.ParseQueryString(Request.QueryString.ToString()); nameValues.Set(“page”, “2”); string url = Request.Url.AbsolutePath; string updatedQueryString = “?” + nameValues.ToString(); Response.Redirect(url + updatedQueryString); The ParseQueryString method returns a NameValueCollection (actually it really returns … Read more

HttpContext.Current.User.Identity.Name is always string.Empty

FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //”” The problem you have is at this point you’re only setting the authentication cookie, the IPrincipal that gets created inside the forms authentication module will not happen until there is a new request – so at that point the HttpContext.User is in a … Read more

Default redirect for Error 404

This is how you configure a custom 404 error page for both ASP.NET and non-ASP.NET requests: <configuration> <system.web> <compilation targetFramework=”4.0″ /> <customErrors mode=”On” redirectMode=”ResponseRewrite”> <error statusCode=”404″ redirect=”http404.aspx” /> </customErrors> </system.web> <system.webServer> <httpErrors errorMode=”Custom”> <remove statusCode=”404″/> <error statusCode=”404″ path=”/http404.aspx” responseMode=”ExecuteURL”/> </httpErrors> </system.webServer> </configuration> As others already pointed out, you should not use an HTTP redirection to … Read more

IIS AAR – URL Rewrite for reverse proxy – how to send HTTP_HOST

This post has the answer – Modifying headers with IIS7 Application Request Routing Need to enable preserveHostHeader – can’t see how you do that in the UI but this works Run this from command line to update Machine/webroot/apphost config %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost