How do I configure extensionless URLs with the Visual Web Development server? - asp.net

I'm using Visual Studios' built-in ASP.NET Development Server (VWD) to test my web site during development.
I would like this ASP.NET web site to use extensionless URLs (pages don't require the aspx extension). Ordinarily I would configure a custom 404 in IIS that directs to an ASPX page. How would I do this with VWD?
P.S. This is not an ASP.NET MVC web site.

Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.
(full article here)
Note: this requires IIS7 as it is using the system.webServer section of the web.config.
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
<urlrewritingnet rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--Enable HTM(L) Extensions-->
<add name="pageHTML"
virtualUrl="^~/(.+).htm(.*)"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
<!--Fix the WebResource JS Error-->
<add name="WebResourceFix"
virtualUrl="^~/WebResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/WebResource.axd$1"
ignoreCase="true"/>
<!--Fix the ScriptResource JS Error-->
<add name="ScriptResource"
virtualUrl="^~/ScriptResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/ScriptResource.axd$1"
ignoreCase="true"/>
<!--Allow Extensionless Page Extensions-->
<add name="pageExtensionless"
virtualUrl="^~/(.+)$"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
</rewrites>
</urlrewritingnet>

There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:
http://localhost:2181/Default
<%# Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello World
</div>
</form>
</body>
</html>

If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.
I posted some example code in a previous question.

All you need to do is add the module in two different places within your web.config...
<system.web>
<pages theme="Default" />
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRewriteModule"/>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7

Related

Browser Link In Visual Studio Is Not Working

I'm trying to launch my web application (asp.net MVC) with debugging mode using Browser Link To Enable Edit Operations during Browser
but actually when i try to do this (Browser Link Not Working and it ask me to register the page inspector in the Web.Config)
Edit
and when i add the following to web.config nothing Happens
<add key="VisualStudioDesignTime:Enabled" value="true" />
<add key="PageInspector:ServerCodeMappingSupport" value="Enabled"/>
still i can't see that any browser connect through Browser Link
with knowledge that I Have Enabled debug=true in web.config
<compilation debug="true" targetFramework="4.6" />
and knowing that i have uninstall web essentials Package
I found this post very useful.
<system.webServer>
<handlers>
<add name="Browser Link for HTML" path="*.html" verb="*"
type="System.Web.StaticFileHandler, System.Web, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
resourceType="File" preCondition="integratedMode" />
</handlers>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Take care in that the <modules> element might already exist.
Add the following in your web.config:
<appSettings>
<add key="VisualStudioDesignTime:Enabled" value="true" />
<add key="PageInspector:ServerCodeMappingSupport" value="Enabled"/>
</appSettings>

Url Rewriting in asp.net doesn't work for me

I am having the below URL and code to change the URL to my custom name in URL. It doesn't return any error but the URL not change.
I want the output like this
From : Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7
To : Frm_AdminHome/
My Webconfig code is here.
Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7 //Query string will be change in every time.
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0" />
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<rewriter>
<rewrite url="~/Frm_AdminHome/(.+).aspx" to="~/Frm_AdminHome.aspx" />
</rewriter>
Rewrite is a process where requested url is not changed and another page is delivered. For example, when you need to call /Frm_AdminHome, but execute /Frm_AdminHome.aspx?something without changing the url then you need following rewrite rule
<rewrite url="^/Frm_AdminHome/?$" to="/Frm_AdminHome.aspx?something" processing="stop" />
If you need to change url from Frm_AdminHome.aspx?something to Frm_AdminHome/, this is called redirect and you need to use the redirect rule
<redirect url="~/Frm_AdminHome.aspx\?.*" to="~/Frm_AdminHome" />
This should redirect
From : Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7
To : Frm_AdminHome/
Refer to http://urlrewriter.net/index.php/support for more details.
If configuration above is not working and you do not see any change then it's most likely that UrlRewriter module is not active. For example, if you run in integrated pool mode you might need to add
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<!--<modules runAllManagedModulesForAllRequests="true" />-->
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter"
type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</modules>
</system.webServer>
P.S.
For IIS 7+ there is a buit-in URL Rewrite Module
P.P.S.
To get querystring or rawurl use
QueryString <%=Request.QueryString.ToString() %> <br />
RawUrl <%=Request.RawUrl %>

Report Viewer Control (Web) Shows Blank Report

I have a web form containing a ReportViewer control, a DIV element so I can see that the page actually renders. I see that my page properly loads, I see the report service being accessed in Fiddler, but there is never anything displayed.
At present, I'm using a report with static text, no queries on it, in order to ensure that I isolate the issue.
My page is as follows:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="PeopleNet.Web.Views.Reports.ReportViewer" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/scripts/jquery-1.7.2.js" />
<asp:ScriptReference Path="~/scripts/fixReportViewer.js" />
</Scripts>
</asp:ScriptManager>
<div>
This is the report viewer page...
</div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>
</form>
</body>
</html>
The code to display the report is:
protected void Page_Load(object sender, EventArgs e)
{
this.ReportViewer1.ServerReport.ReportServerUrl = ConfigurationFacade.ReportServerUri;
this.ReportViewer1.ServerReport.ReportPath = { path to report name };
this.ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerCredentials(); // custom class implementing IReportServerCredentials as described in various places around the web, including SO
this.ReportViewer1.ServerReport.Refresh();
}
My web.config file is configured with the HttpHandlers as required:
<system.web>
<!-- abbreviated... -->
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" validate="false" />
</httpHandlers>
</system.web>
And :
<system.webServer>
<!-- abbreviated... -->
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</handlers>
</system.webServer>
The server runs Windows 2008 and SQL Server 2008 R2.
I am using the SQL Server 2012 version of the viewer, as we are in the process of updating our environments to 2012.
I have repeatedly verified that the report is accessible from the ReportManager, with no issues whatsoever.
I have been attempting to access this in IE9, having seen various issues stated with other browsers.
I am presently (for testing only) passing my credentials as the report server credentials. I am a Reporting Services Administrator, as well as a member of the server administrators group on the server.
I have checked both the event log and the ReportServerService log, and have found nothing amiss.
UPDATE: Looks like when change the AsyncRendering to false, and ensure that I don't try to "SetParameters" with an empty collection, this gets mostly cleared up:
this.ReportViewer1.AsyncRendering = false;
What am I missing in the configuration/code here?
My solution to this issue was related to trying to set the report viewer height to 100%. This resulted in no report showing. Changing the height to a px value (ie 900px) got the reportviewer working.
There is this blog entry on MSDN that discusses how asynchronous rendering works.
Additionally, it mentions that (as was said in the comments) synchronous rendering embeds the content in the page, while asynchronous rendering renders the content in a frame. The size of the frame is "difficult...to calculate" and the SizeToReportContent property is ignored.
Since your report won't display unless it is synchronously rendered, the issue must be in the use of frames.
In the article mentioned in the comments, asynchronously rendering the report will collapse the control height to zero pixels if a relative height is used. This could explain why nothing is displayed. You might try specifying a height for the control. There are other suggestions in that article as well.
That's assuming that your issue is in the SQL Server 2008 R2 SSRS version, which I believe draws from VS 2008. SQL Server 2012 SSRS I think draws on VS 2010, which is not supposed to have those issues, so when you finish your upgrade, this issue might go away.
I had exactly the same symptom: A report was rendered with a completely blank page. For me that was the case in production, but it worked in development environment.
The report had two parameters and in the RDL both without having default values specified. When calling the report in the aspx code behind I had accidentally passed only one parameter. The second parameter had a default value set on the Report Server of the development machine but not in production. (Yes, the Report Server allows to specify parameter defaults independently from the default settings in the RDL file.) As a result the report rendered in development but not in production.
I found this by looking at the response XML with Fiddler. It contained an element telling me that a parameter value was invalid. Unfortunately the Report Viewer itself doesn't show any error message about the missing parameter and just displays a blank page - which makes the root of the problem difficult to find.
My report was showing blank as well. I played with the properties and it finally showed up.
Changing the ProcessingMode property on the ReportViewer control in the aspx page worked for me:
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
Width="100%" ProcessingMode="Remote">
</rsweb:ReportViewer>
This is what I have:
<rsweb:ReportViewer ID="ReportViewer1" runat="server" ZoomMode="PageWidth"
Font-Names="Verdana" Font-Size="8pt" Width="100%" ProcessingMode="Remote"
ShowParameterPrompts="False" ShowToolBar="True" ShowCredentialPrompts="False"
ShowFindControls="False" ShowZoomControl="False" CssClass="ReportViewer">
</rsweb:ReportViewer>
web.config:
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
...
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
</configuration>
There are several problems when you get blank reports:
IIS Pipeline; IIS 6 vs IIS7 and above
Make sure you have correctly registerd HttpHandler
IIS7 settings
<system.webServer>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</handlers>
More details
If missed the correct registration you can try to switch IIS application pool into Classic mode
If your registration is Ok you should be able to use Integrated mode
Another Handler interferes with ReportViewer
In my case it was Glimpse. Glimpse is a very powerful tool and it works fine together with ReporViewer on developer machine but it has problems on deployed customer server. Solution was easy, jst remove all glimse settings from web.config

Unable to get dotLess to work

I am using dotLess.
I followed all their instructions (which seems simple enough) it's only 4 steps :)
my minimal web.config looks like this:
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
</configSections>
<dotless minifyCss="false" cache="true" />
<system.web>
<httpHandlers>
<add type="dotless.Core.LessCssHttpHandler, dotless.Core" validate="false" path="*.LESS" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="LessHttpHandler" type="dotless.Core.LessCssHttpHandler, dotless.Core" preCondition="integratedMode" path="*.less" verb="*" />
</handlers>
</system.webServer>
</configuration>
I've added my .less files in my content folder (i am using ASP.NET MVC - Razor ViewEngine)
my layout has a link to my .less include file:
<link rel="stylesheet/css" type="text/css" href="#Url.Content("~/Content/Site.less")" />
I have also added the a reference in my web application to dotless.Core.dll
Yet despite all of the when i do a simple styling of the page's body backround to black, nothing happens, for some reason it aint kicking in.
Am i missing something here?
Do you set the httphandler to run on requests? Add this:
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
</configuration>
have you tried accessing the Site.less file directly with your browser? If there is a syntax error in your less it will be output there..
If you get a 404 on that page the web.config is the problem, but I can't find anything wrong with it at the moment.
Are you running in Cassini or are you running on IIS7?
I'm not sure if this may be the cause, but in your link tag, rel value should be "stylesheet", not "stylesheet/css".
Also, I don't use ASP MVC but don't you need a tag around the Url.Content, like so?
<%= Url.Content("~/Content/Site.less") %>
Have you tried setting the cache to false? On some machines I've had issues with it.

WebForms page inside of Orchard CMS Application

I am attempting to add a aspx page inside orchard cms application. I have placed my aspx page in a folder /Web/Test.aspx in the Orchard.Web web application. Note: I am using the source of orchard at the moment. I also added the necessary handler, as posted in this post, in the system.webServer tag in the config. Currently getting 'The resource cannot be found.'
Here is what my web config looks like around the system.webServer tag.
<configuration>
<system.webServer>
<handlers accessPolicy="Script">
<!-- already listed, not added by me -->
<clear/>
<!-- added by me -->
<add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script">
<!-- already listed, not added by me -->
<add name="NotFound" path="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script"/>
</handlers>
</system.webServer>
</configuration>
I'm I missing anything?
Remove the clear tag and the Notfound handler and then try again.

Resources