URL Routing not working on server in Asp.Net - asp.net

Here DataList.aspx & Details.aspx is inside directory v1, so i tried routing in two ways but nothing is working on server.
Global.asax
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("Route1",
"Category/{Brand}.html","~/DataList.aspx");
RouteTable.Routes.MapPageRoute("Route2",
"Category/{Brand}/{Title}.html","~/v1/Details.aspx");
}
I am using this routing in hyperlink inside listview. Url is generated correctly, but when i click on link it shows
"404 - File or directory not found."
I have also added this in web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e42" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e42" />
</handlers>
</system.webServer>

Related

body of report not visible

Using Visual Studio 2015 mvc 5 application. I have created an SSRS report with Visual Studio 2012 that does not take any parameters (yet). I used nuget to add ReportViewerForMvc. I went through an online tutorial to create ReportTemplate.aspx etc. I'm using Forms Authentication so I changed my data sources to use a static SQL Login in SSRS. When I run the report manually I get 151 pages. When I run it through the application the toolbar at the top reads 1 of 151 pages. However, I can't see the body of the report and all the buttons on the toolbar are disabled. I've been fiddling with the control properties in the ReportTemplate.aspx.cs (code behind) and the ReportTemplate.aspx but nothing seems to change it.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
String reportFolder = System.Configuration.ConfigurationManager.AppSettings["SSRSReportFolder"].ToString();
String reportUri = System.Configuration.ConfigurationManager.AppSettings["SSRSReportUri"].ToString();
rvSiteMapping.Height = Unit.Pixel(2000);
rvSiteMapping.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
rvSiteMapping.ServerReport.ReportServerUrl = new Uri(reportUri); // Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportPath = String.Format("/{0}/{1}", reportFolder, Request["ReportName"].ToString());
rvSiteMapping.ServerReport.Timeout = 320000;
rvSiteMapping.ServerReport.Refresh();
rvSiteMapping.ShowReportBody = true;
rvSiteMapping.ShowToolBar = true;
rvSiteMapping.SizeToReportContent = true;
rvSiteMapping.Enabled = true;
rvSiteMapping.Visible = true;
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}
Package Entries:
<package id="MicosoftReportViewerWebForms_v11" version="1.0.1" targetFramework="net451" />
<package id="ReportViewerForMvc" version="1.0.0" targetFramework="net451" />
Web.Config:
<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>
...
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<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>
Thanks
Lee

How Load View Files from bin Folder in Asp.net MVC

i work on asp.net mvc project and i transfer some view files to other project and enable "copy always" for them (to copy in bin folder of main project).
i create a custom view engine :
public class CMSViewEngine : WebFormViewEngine
{
public CMSViewEngine()
{
MasterLocationFormats = new string[]
{
"~/bin/Views/{1}/{0}.master",
"~/bin/Views/Shared/{0}.master"
};
ViewLocationFormats = new string[]
{
"~/bin/Views/{1}/{0}.cshtml",
"~/bin/Views/{1}/{0}.vbhtml",
"~/bin/Views/Shared/{0}.cshtml",
"~/bin/Views/Shared/{0}.vbhtml",
"~/bin/Views/{1}/{0}.aspx",
"~/bin/Views/{1}/{0}.ascx",
"~/bin/Views/Shared/{0}.aspx",
"~/bin/Views/Shared/{0}.ascx"
};
}
}
then added to mvc ViewEngine in global.ascx
ViewEngines.Engines.Add(new CMSViewEngine());
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
but my problem is: for showing view i get under exception:
The view at '~/bin/Views/Forms/Index.cshtml' must derive from
ViewPage, ViewPage, ViewUserControl, or
ViewUserControl.
i try add web.config to view folder and also try add #inherits System.Web.Mvc.WebViewPage to view files but not worked.
my web.config file for bin view files is :
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="TestProj.ContactFormApp" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
how can resolve this problem to load view file?
Resolved:
I must extend CMSViewEngine class from RazorViewEngine class (instead of WebFormViewEngine) to work correctly.
It looks like you are using WebFormViewEngine, if that is the case you should not registere razor view files in WebFormViewEngine, your CMSViewEngine class should only contain WebForm based view files extensions like:
public class CMSViewEngine : WebFormViewEngine
{
public CMSViewEngine()
{
MasterLocationFormats = new string[]
{
"~/bin/Views/{1}/{0}.master",
"~/bin/Views/Shared/{0}.master"
};
ViewLocationFormats = new string[]
{
"~/bin/Views/{1}/{0}.aspx",
"~/bin/Views/{1}/{0}.ascx",
"~/bin/Views/Shared/{0}.aspx",
"~/bin/Views/Shared/{0}.ascx"
};
}
}
Just in case you are doing it with .NET Core you can just put the path to the view in bin folder and pass your model through.
return View(#"bin\Debug\netcoreapp1.0\Views\Test.cshtml", new ReportLibrary.Person());

report viewer is blank

work with visual studio 2012. I need to load my report viewer inside a div in my web page. But it would be blank. It works fine a separate web page alone, but when I want to load it inside a section inside my content page, it is blank. The part of my code which works with report viewer:
// add a div dynamically
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("id", "chart05");
div.Attributes.Add("runat", "server");
div.Attributes["class"] = "chartItem";
sanaChartsContainer.Controls.Add(div);
Microsoft.Reporting.WebForms.ReportViewer viewer = new Microsoft.Reporting.WebForms.ReportViewer();
viewer.Attributes.Add("id", "ReportViewer");
viewer.Attributes.Add("runat", "server");
viewer.Attributes.Add("Font-Names", "Verdana");
viewer.Attributes.Add("Font-Size", "8pt");
viewer.Attributes.Add("Height", "50px");
viewer.Attributes.Add("ProcessingMode", "Remote");
viewer.Attributes.Add("WaitMessageFont-Name", "Verdana");
viewer.Attributes.Add("WaitMessageFont-Size", "14pt");
viewer.Attributes.Add("Width", "50px");
viewer.Attributes.Add("AsyncRendering", "false");
viewer.ServerReport.Refresh();
viewer.ShowParameterPrompts = false;
Uri baseUri = new Uri("http://mdb165.cbi.net/reportserver");
viewer.ServerReport.ReportServerUrl = baseUri;
viewer.ServerReport.ReportPath = "/SanaII/report005";
System.Web.UI.ScriptManager scriptManager = new ScriptManager();
Page page = new Page();
System.Web.UI.HtmlControls.HtmlForm form = new HtmlForm();
//div.Controls.Add(scriptManager);
div.Controls.Add(viewer);
My web config is:
<configuration>
<system.web>
<compilation debug="true">
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</buildProviders>
</compilation>
<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>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<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>
</configuration>
I also added script manager to my page,
but report viewer is blank.
I also tried to load it directly in my content page as below shows:
but this is also doesn't work and is blank.
Please give me help.
Have you tried adding if(!IsPostBack) in your Page_Load?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetDate();
BindCustomerCategory();
BindUtility();
}
}
OR if this will not work. Double check the aspx of your report page you might forgot something there..

FederatedAuthentication.WSFederationAuthenticationModule is null at runtime

I am trying to subcribe to RedirectingToIdentityProvider event in Application_Start() , but FederatedAuthentication.WSFederationAuthenticationModule is null
code
protected void Application_Start()
{
FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
}
Try doing this - works for me.
void Application_Start()
{
FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;
}
void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
}
Here is a precision for .net 4.0
<system.web>
<httpModules>
<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</httpModules>
</system.web>
....
<system.webServer>
<modules>
<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
</modules>
</system.webServer>
It sounds like you may be missing the WSFederationAuthenticationModule in your configuration. Make sure you have this in system.webServer\modules:
<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
And this in system.web\httpModules:
<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Read here for more information.
Make sure in your Global.asax you referencing the
System.IdentityModel.Services.WSFederationAuthenticationModule
and not:
Microsoft.IdentityModel.Web.FederatedAuthentication.WSFederationAuthenticationModule
The wrong (inconsistent between web.config and global.asax) reference will cause the WSFederationAuthenticationModule be null.

IIS 7 handler mapings & asp.net *.htm page routing with WebForm. How to route *.htm like *.aspx?

I am trying to make the *.htm files processable by .net to route this extension, but I am unable until now. I search through tons of results on google/bing, I found something to make the mapping and to route it, but it's not working.
Note that I am using webForm, not mvc.
The mapping set in IIS is Managed Handler : path=*.htm, Handler=System.Web.UI.SimpleHandlerFactory
Here the code I am using.
Am I missing something?
Thanks!
//Web.config
<system.web>
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModue,System.Web.Routing,Version=4.0.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
<httpHandlers>
<add verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler,System.Web, Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.htm" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
//global.asax.cs
void RegisterRoutes(RouteCollection routes){
routes.Ignore("{ressources}.asd/{*pathInfo}");
routes.MapPageRoute("OnlineHelp", "Help/Content/{HelpFile}.htm", "~/Default.aspx");
routes.MapPageRoute("Default", "", "~/Default.aspx",true);
}

Resources