getting The length of the URL for this request exceeds the configured maxUrlLength value for only 4 lines of data after publish api on iis - asp.net-mvc-4

I have asp.net web api MVC4 which test it out on POSTMAN local host and it works fine,when i publish it on server and check on Postman i see The length of the URL for this request exceeds the configured maxUrlLength value,i reduced the number of data to one! but still the same error
my class:
public IEnumerable<myStat10> Get(string id, string dttimeFrom, string dttimeTo)
{
string format = "ddMMyyyy";
DateTime fromdate = DateTime.ParseExact(dttimeFrom, format, CultureInfo.InvariantCulture);
DateTime todate = DateTime.ParseExact(dttimeTo, format, CultureInfo.InvariantCulture);
IPAddress turip = IPAddress.Parse(id);
var rslt = (from m in _context.stat10
where m.m_turbine_id ==id && m.m_time_stamp >= fromdate && m.m_time_stamp <= todate
select new myStat10
{
m_time_stamp=m.m_time_stamp,
m_turbine_id=m.m_turbine_id,
m_wind_speed=m.m_wind_speed,
m_rpm =m.m_rpm,
m_power=m.m_power,
m_t_blade_1=m.m_t_blade_1,
m_t_blade_2=m.m_t_blade_2,
}).Take(1).toList();
its my webApiConfig:
config.Filters.Add(new BasicAuthenticationAttribute());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
web config:
<httpRuntime maxUrlLength="209715" />
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.7.1" />
<authentication mode="None" />
<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.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>

Update the maxUrlLength property in your web.config: https://learn.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxurllength?view=netframework-4.8
Try using the max value allowed which is 209715.

Related

Update App.config file using vb.net

I have an App.config with this code
<appSettings>
<add key="dataPath" value="" />
<add key="databaseConnectionString" value="MultipleActiveResultSets=True;SERVER=;DATABASE=;UID=;PWD=" />
<add key="APIaddress" value="" />
<add key="Timer" value="1" />
<add key="BufferSize" value="100" />
<add key="fisrtConfig" value="1" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
I can access to these values with this code
Srv = System.Configuration.ConfigurationManager.AppSettings("APIaddress").ToString()
timer = CInt(System.Configuration.ConfigurationManager.AppSettings("TimerEsecuzione").ToString())
connectionString = System.Configuration.ConfigurationManager.AppSettings("databaseConnectionString").ToString()
BufferSize = System.Configuration.ConfigurationManager.AppSettings("BufferSize").ToString()
isFirstConfig = IIf(System.Configuration.ConfigurationManager.AppSettings("fisrtConfig").ToString() = 1, True, False)
During my code run, I would to update one of these. I tried differents type of code but no one can update it. These are code I tried:
First
Dim configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim settings = configFile.AppSettings.Settings
settings("fisrtConfig").Value = 0
configFile.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name)
Second
ConfigurationManager.AppSettings.Item("fisrtConfig") = 0
Can you help me please?

WCF http binding

I create a wcf service application and a asp.net mvc project(as client). I added my wcf service via Add Service Reference file to my asp.net mvc reference. I use Entity Framework to connect DB in my wcf application. I have a UserManagement.svc.cs service.
This is my UserManagement.svc.cs codes:
public class UserManagement : IUserManagement
{
iFlowEntities db = new iFlowEntities();
public void AddRole(role role)
{
db.roles.Add(role);
db.SaveChanges();
}
public List<role> RoleList()
{
List<role> roles;
roles = db.roles.ToList();
return roles;
}
}
And I use this service in my UserController in RoleList() action in asp.net mvc and this is that action code:
public ActionResult RoleList()
{
IList<UserManagement.role> roles = new List<UserManagement.role>();
roles = UserClient.RoleList();
return View("_RoleList",roles);
}
and UserClient variable define in controller body like: UserManagement.UserManagementClient UserClient = new UserManagement.UserManagementClient();
When I run asp.net project I get this error:
An error occurred while receiving the HTTP response to
http://localhost:1730/UserManagement.svc. This could be due to the
service endpoint binding not using the HTTP protocol. This could also
be due to an HTTP request context being aborted by the server
(possibly due to the service shutting down).
I googled and see multiple answer and test them but don't have result for me and this answer like this and this and this.
And this is my wcf service config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxRequestLength ="262144" executionTimeout="103600" targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="iFlowEntities" connectionString="metadata=res://*/Model.DBContext.csdl|res://*/Model.DBContext.ssdl|res://*/Model.DBContext.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=iFlow;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<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>
Edited:
Yes, I add DataContract and DataMember to my class and ServiceContract and OperationContract.
This is my client config file:
<?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=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<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="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IUserManagement" />
<binding name="BasicHttpBinding_IDepartmentManagement" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1730/UserManagement.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserManagement"
contract="UserManagement.IUserManagement" name="BasicHttpBinding_IUserManagement" />
<endpoint address="http://localhost:1730/DepartmentManagement.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDepartmentManagement"
contract="DepartmentManagement.IDepartmentManagement" name="BasicHttpBinding_IDepartmentManagement" />
</client>
</system.serviceModel>
</configuration>
I think this issue is an Entity Framework matter. Whenever you serialize an entity in WCF service, it tries to load child entities as well, while WCF can't serialize them. To solve this issue simply disable Proxy Creation option in DbContext constructor:
public class DatabaseEntities : DbContext
{
public DatabaseEntities()
{
Configuration.ProxyCreationEnabled = false;
}
}

Login failed for user in MVC application

Hello I am trying to make a user authentication page, I added to my web.config something like this:
<authentication mode="Forms">
<forms loginUrl="~/User/Login" timeout="2880">
</forms>
</authentication>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear />
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
<roleManager enabled="true" />
I connect to database with sqlauthentication mode like you can see in Server Explorer but when I try to start the application I get an error.
Here is my connection string to:
<add name="DefaultConnection" connectionString="Data Source=db-mssql;Initial Catalog=inzS9776;Persist Security Info=True;" providerName="System.Data.SqlClient" />

imageresizer remote reader plugin only displays the remote image if no query strings are present in URL

I'm trying to resize/crop the images stored on one of our servers and use them on another, also our server. Image resizer is running on www.aapg.org. Remote images are stored on assets.aapg.org.
Not sure why it doesn't work. I followed the process outlined in http://imageresizing.net/plugins/remotereader -- everything looks OK. I tried both a signed remote URL and human-friendly syntax, and neither worked for me.
Here are the plugins from the Web.config file I'm using:
<add name="MvcRoutingShim" />
<add name="DiskCache" />
<add name="SeamCarving" />
<add name="SimpleFilters" />
<add name="PdfRenderer" downloadNativeDependencies="true" />
<add name="DropShadow" />
<add name="WhitespaceTrimmer" />
<add name="PrettyGifs" />
<add name="AnimatedGifs" />
<add name="WebPEncoder" />
<add name="WebPDecoder" />
<add name="RemoteReader" />
<add name="CloudFront" />
And the remote reader plugin configuration ('xxxxxxxxxxxxxxxxxxxxxx' is obviously not what I'm using):
<remotereader signingKey="xxxxxxxxxxxxxxxxxxxxxx" allowAllSignedRequests="false" allowRedirects="5">
<allow domain="aapg.org" />
<allow domain="assets.aapg.org" />
</remotereader>
Can anyone tell me what I'm doing wrong? Or what I'm missing?
Thanks in advance!

MVC4 Intranet site IIS 7, cannot display the webpage

I have been at this for hours and still have not figure out what I am doing wrong. I created an MVC4 intranet site and now I am ready to deploy it to IIS on our web server. I setup a site called Portal and from Visual Studio I have performed the 1 click publish using the file system method. The files copied successfully to my site. In IIS I changed authentication to Windows and disabled Anonymous authentication. I even went into my application pool and changed the Load User Profile = true (not sure if I needed to do that). I then hit browse Portal on *:88 and I receive Internet Explorer cannot display the webpage. I checked my Modules and I see UrlRoutingModule-4.0 is managed and inherited. I must be overlooking an obvious setting as this is my first web site. Any help is appreciated. Thank you.
physical path = c:\inetpub\wwwroot\Portal
Site name and Application Pool = Portal (.Net 4 and Pipeline mode: integrated)
type = http
Host name = Portal
Port = 88 (80 was already used and did not work)
IP Address = *
UPDATE: Webconfig (i have custom roles) and Routconfig
<system.web>
<roleManager enabled="true" defaultProvider="DbRoleProvider">
<providers>
<clear />
<add name="DbRoleProvider"
applicationName="Portal"
type="Portal.WebUI.Infrastructure.DbRoleProvider"
connectionStringName="PortalEntities" />
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<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.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<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>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "RequestInfo", action = "Index", id = UrlParameter.Optional }
);
}
so after more experimentation and research I found my problem, and it was a result of never doing this before.
My first problem was I included a host name when I was setting up my application. So when I tried to browse to www.portal.com:85 on the server it did not understand that address and could not connect to anything. However, when I removed the host name and typed in http://localhost:85 it worked. I will have to get with my infrastructure team to set that up.
My second problem was security to our SQL Server. I did not know I had to setup a login for the application pool name. I used the second answer from this post Login failed for user 'IIS APPPOOL\ASP.NET v4.0' because I did not want to change the identity to LocalSystem. Once I setup a login under the SQL Server security the site was functioning. Is that the correct way of doing it?
It would be helpful if you disabled friendly error messages in IE. In "Internet Options" on the Advanced tab, under Browsing deselect "Show friendly HTTP error messages". Then try again. Hopefully then you'll see what the actual issue is as an HTTP status code. Can it not find the server, are you getting a 404 (page not found), a 401 unauthorized, a 500, etc.
With that information it will be much easier to diagnose.