Here's my web.config snippet, from the config file that's deeper inside the project than the other.
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="MVCWebsite.Models" />
<add namespace="MVCWebsite.ViewModels" />
<add namespace="MVCWebsite.Helpers" />
<add namespace="MVCWebsite.Extensions" />
<add namespace="Mvc.Mailer" />
All of the above exception .Models are accessible in my views, why can I not access Models? Is there something that prevents me from doing this? I want to access static property on these classes.
Related
I have an ASP .NET application. I am trying to log in but it keeps asking for login even though my credential is correct and have sufficient privileges to access to the required database. I tried all solutions which I look around on the internet include changing Visual Studio project property, move NTML of Window Authentication to top, disabled Anonymous Authentication, added IIS_IUSRS, Authenticated Users, IIS user, my credential to Folder Permission. This application was not well documented, from my boss, he believes this app use Windows Authentication due to internal usage purpose. It has two parts, the first part is the app and the second is the engine. The first part app Windows Authentication is fine. I put the engine part under the same folder where the app is located in IIS. The engine is built on my dev local computer then copy to the server. My purpose to learn what the code does. I am trying to spin up the second part, is the engine, however, it seems odd to me though. I got 401.1 - Unauthorized: Access is denied due to invalid credentials if I hit Esc or Cancel the login prompt. Appreciate any help or suggestion.
FYI: The app and engine are applications stay under the website.
Website > App + Engine
IIS 7.5, Windows Server 2008 R2, VS2015, maybe ASP .NET MVC (not sure)
Here is my Web.config file for the engine
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SecurityDatabase" connectionString="Data Source=TEX_ITY;Initial Catalog=TEx;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<!-- ASP.NET CONFIG -->
<add key="webpages:Version" value="3.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="aspnet:MaxHttpCollectionKeys" value="50000" />
<!-- TEx -->
<!-- SERVICES CONFIG -->
<add key="EmailServiceUrlFormat" value="https://{0}/Services/Email/TExEmailService.svc" />
<add key="DataExecutionServiceUrlFormat" value="https://{0}/Services/DataExecution/TExDataExecutionService.svc" />
<add key="AccountProcessingServiceUrlFormat" value="https://{0}/Services/AccountProcessing/TExAccountProcessingService.svc" />
<add key="ElectronicFileTransmissionServiceUrlFormat" value="https://{0}/Services/Filing/TExElectronicFileTransmissionService.svc" />
<!-- LOGGING CONFIG -->
<add key="MasterLogLevel" value="Trace" />
<add key="MaxStoredLogCount" value="1000" />
<!-- IMPORT CONFIG -->
<add key="ImportFileEEThreshold" value="50000" />
<add key="ImportLogsStatistics" value="true" />
<add key="ThemeName" value="Forest" />
<add key="RoutesXmlFilePath" value="~/App_Data/Routes.xml" />
<add key="RotatedTextBaseUrl" value="~/TextAsImage.axd" />
<add key="FileDownloadBaseUrl" value="~/FileDownload.axd" />
<add key="CompanyImportSchema" value="~/App_Data/Schemas/CompanyImport.xsd" />
<add key="CompanyImportSchema2" value="~/App_Data/Schemas/New Schema/CompanyImport.xsd" />
<add key="TabDelimitedCompanySetupSchema" value="~/App_Data/Schemas/TabDelimitedCompanySetup.xsd" />
<add key="TabDelimitedTaxSetupSchema" value="~/App_Data/Schemas/TabDelimitedTaxSetup.xsd" />
<add key="TabDelimitedTaxDetailSchema" value="~/App_Data/Schemas/TabDelimitedTaxDetail.xsd" />
<add key="TabDelimitedCompanySetupSampleXml" value="~/App_Data/SampleXmls/CompanySetupSampleFile.xlsx" />
<add key="TabDelimitedTaxSetupSampleXml" value="~/App_Data/SampleXmls/TaxSetupSampleFile.xlsx" />
<add key="TabDelimitedTaxDetailSampleXml" value="~/App_Data/SampleXmls/TaxDetailSampleFile.xlsx" />
<add key="TransformGenerateUnMergedTaxDetails" value="~/App_Data/Transforms/GenerateUnMergedTaxDetails.xslt" />
<add key="TransformGenerateMergedTaxDetails" value="~/App_Data/Transforms/GenerateMergedTaxDetails.xslt" />
<add key="TransformGenerateMergedTaxDetailsWithXmlns" value="~/App_Data/Transforms/GenerateMergedTaxDetailsWithXmlns.xslt" />
<add key="CompanyImportSchemav1.00" value="~/App_Data/Schemas/CompanyImportv1.00.xsd" />
<add key="CompanyImportTransformv1.00to1.01" value="~/App_Data/Schemas/CompanyImportv1.00to1.01.xslt" />
<add key="CryaReportSummaryReportSchema" value="~/App_Data/Schemas/SummaryReport.xsd" />
<add key="TExCoverLetterDefaultTemplate" value="~/App_Data/TExCoverSheet.docx" />
<add key="TransformerDirPath" value="~/Uploads/TEx-Engine/Release/Transformers" />
<add key="ReportElectronicFilingSpecDirPath" value="~/Uploads/TEx-Engine/Reports/Electronic/Specs" />
<add key="ReportPaperFilingAgencyReportDirPath" value="~/Uploads/TEx-Engine/Reports/Paper/AgencyReport" />
<add key="ReportPaperFilingCustomReportDirPath" value="~/Uploads/TEx-Engine/Release/CustomReport" />
<add key="ReportPaperFilingSpecDirPath" value="~/Uploads/TEx-Engine/Reports/Paper/Specs" />
</appSettings>
<location path="." inheritInChildApplications="false">
<system.web>
<pages controlRenderingCompatibilityVersion="4.0" enableViewState="false">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Crya.Core.Extensions" />
<add namespace="Crya.Core.Linq.Expressions" />
<add namespace="Crya.Core.Utils" />
<add namespace="Crya.Core.Web.Data" />
<add namespace="Crya.Core.Web.Extensions" />
<add namespace="Crya.Core.Web.Mvc.Assets" />
<add namespace="Crya.Core.Web.Mvc.Assets.Extensions" />
<add namespace="Crya.Core.Web.Mvc.Extensions" />
<add namespace="Crya.Core.Web.Mvc.Utils" />
<add namespace="Crya.Core.Web.Mvc.Utils.Builders" />
<add namespace="TEx.Ui.Web.Extensions" />
<add namespace="TEx.Ui.Web.Models.Data" />
<add namespace="TEx.Ui.Web.Models.Data.Controls" />
<add namespace="TEx.Ui.Web.Models.Data.Domain" />
<add namespace="TEx.Ui.Web.Utils" />
<add namespace="TEx.Ui.Web.Utils.Builders" />
<add namespace="Telerik.Web.Mvc.Extensions" />
</namespaces>
<controls>
<add tagPrefix="te" assembly="TEx.Ui.Web" namespace="TEx.Ui.Web.Models" />
</controls>
</pages>
<httpHandlers>
<add verb="GET" path="TextAsImage.axd" type="Crya.Core.Web.Imaging.RotatedTextGenerator" validate="false" />
<add verb="GET" path="FileDownload.axd" type="Crya.Core.Web.Content.DownloadFileHandler" validate="false" />
<add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
<add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
<httpModules>
<add name="TExAuthentication" type="TEx.Shared.Security.TExAuthenticationModule, TEx.Shared" />
</httpModules>
<siteMap defaultProvider="CombinedSiteMapProvider">
<providers>
<add name="CombinedSiteMapProvider" type="TEx.Ui.Web.Navigation.SiteMap.TExSiteMapProvider" siteMapFile="~/Web.sitemap" areaName="" forceLowerCaseUrl="true" forceTrailingSlashUrl="true" />
<add name="EngineSiteMapProvider" type="TEx.Ui.Web.Navigation.SiteMap.TExSiteMapProvider" siteMapFile="~/Areas/Engine/Web.sitemap" areaName="Engine" forceLowerCaseUrl="true" forceTrailingSlashUrl="true" />
</providers>
</siteMap>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="TExAuthentication" type="TEx.Shared.Security.TExAuthenticationModule, TEx.Shared" />
</modules>
<handlers>
<add name="rotatedText" verb="GET" path="TextAsImage.axd" type="Crya.Core.Web.Imaging.RotatedTextGenerator" />
<add name="downloadFile" verb="GET" path="FileDownload.axd" type="Crya.Core.Web.Content.DownloadFileHandler" />
<remove name="asset" />
<add name="asset" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="([^/:]+)(:[^/]*)?" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:0}" appendQueryString="true" />
</rule>
<rule name="Lower Case URLs" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
<rule name="Trailing Slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
<system.web>
<machineKey validationKey="843C54527BD577FCEEF69ABE5B4590BBDE5C035B26CB6B52920061F5221E640B4AB509E9CB22F254C37C1CADE017A34F7DD52582ECC97830F5B81FA954E8B6D0" decryptionKey="97327C072BDBA2FACFBD3526DBF6F277EE368B2DCEB76AE2E42D7538AD95CBFA" validation="SHA1" decryption="AES" />
<authentication mode="Windows">
</authentication>
<authorization>
<!-- <allow users="*" /> -->
<deny users="?" />
</authorization>
<compilation targetFramework="4.5" debug="true" batch="false" optimizeCompilations="true">
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<httpRuntime maxRequestLength="20480" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<location path="Account/LogOn">
<system.web>
<authorization>
<allow users="?" />
</authorization>
<httpModules>
<remove name="TExAuthentication" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="TExAuthentication" />
</modules>
</system.webServer>
</location>
<location path="~/App_Themes">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<httpModules>
<remove name="TExAuthentication" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="TExAuthentication" />
</modules>
</system.webServer>
</location>
<location path="~/Content">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<httpModules>
<remove name="TExAuthentication" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="TExAuthentication" />
</modules>
</system.webServer>
</location>
<location path="~/Images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<httpModules>
<remove name="TExAuthentication" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="TExAuthentication" />
</modules>
</system.webServer>
</location>
<location path="~/Scripts">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<httpModules>
<remove name="TExAuthentication" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="TExAuthentication" />
</modules>
</system.webServer>
</location>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="" sendTimeout="01:00:00">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<dotless minifyCss="false" cache="true" web="false" />
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
I have a Mvc4 site that was created eith the empty template. How can I now include forms authentication to the site?
I have checked a few books and shearched but i have not come up with any relevant information.
my webconfig looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers></system.webServer>
<connectionStrings>
//
</connectionStrings>
</configuration>
Go to Web.config file in your project, check if the mode type for authentication is "Forms". See below:
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="20" />
</authentication>
</system.web>
The mode type for authentication have 4 defferent types, like below:
Windows
Forms
Passport
None
If you don't see <authentication> element in the Web.config file, add it inside the <system.web> element. Also because you're using empty templates, you need to add some logic for your Form based authentication. Like create Account Controller and Login Action.
I searched here same problem Asp.net - <customErrors mode="Off"/> error when trying to access working webpage, but when i do like it was told, i dont get any reaction same runtimeerror;
Here is my web.config
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" strict="false" explicit="true" />
<authentication mode="None"/>
<compilation targetFramework="4.5" />
<httpRuntime requestValidationMode="2.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages validateRequest="false">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
Seems you have the compilation and authentication tag in there 2 times. Remove the duplicates.
I wrote a UrlHelper and in every view I need to include an using clause:
#using MyWebPage.Helpers
Is there way to avoid it? That would be great if this import automatically.
I added this in web.config as below:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="MyWebPage.Helpers" />
</namespaces>
</pages>
But it wouldn't solve my problem.
There are 2 web.configs in the project.
For Views
For application
You need to include the namespace in proper web.config which is for views.
Once you include it in proper namespace you don't have to include it in every page.
<system.web.webPages.razor>
<host ....>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="MyWebPage.Helpers" />
</namespaces>
</system.web.webPages.razor>
</pages>
Add the namespace into Views/web.config, close all cshtml files, reopen them, voila.
How do I access an extension method in an ASP.Net MVC View? In C# I do
using MyProject.Extensions;
and I remember seeing an XML equivalent to put in a view, but I can't find it anymore.
In View:
<%# Import Namespace="MyProject.Extensions" %>
Or in web.config (for all Views):
<pages>
<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="System.Linq" />
<add namespace="System.Collections.Generic" />
<add namespace="MyProject.Extensions" />
</namespaces>
</pages>
For pages using Razor / WebPages, you can include a using directive in your .cshtml page.
#using MyBlogEngine;