|
Pardon me if this was already mentioned, this is a fairly long thread. But I have a feeling that this case is handled by namespaces for a couple of decades. I mean you can have a POCO for your needs in one namespace and another class for what customers want in the other namespace. And you can map one to another manually or via some tool like Automapper.
Quote: I want a popup asking me which one I want to use.
Also, I have a feeling that you're confusing language and tooling. Is popup some sort of language construct or a feature in IDE? Which one? VS? VS code? Jetbrains rider?
|
|
|
|
|
Hi,
Not sure which forum I need to use for this issue. Currently we are using visual studio 2012 ,Community edition ,net framework 4.0. On our workstations, we installed Visual Studio Enterprise 2019 version. We Should migrate our project to.net framework 4.7.2 in VS2019. When I open project in VS 2019 with .net framework 4.7.2, it is giving the run time error as Authentication error (Project was successfully build without any error). Where the same project worked good on VS2012.
It is showing
"
Exception Details: System.UnauthorizedAccessException: Windows Integrated Security is not enabled
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true">, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
Line 115: {
Line 116:
Line 117: throw new UnauthorizedAccessException("Windows Integrated Security is not enabled");
Line 118: }
Line 119:
"
Where i have enabled windows integrated security .
windows authentication as enables and anonymous authentication as disabled.
Can anyone please help me what changes i need to make over here?
modified 15-Jun-20 6:39am.
|
|
|
|
|
That's an error being thrown by your code, not the framework. Look at the preceeding lines in that method to see why you're reaching that exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When the same code was executed in VS2012 it worked without any error and authentication was true
"void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Context.Request.IsAuthenticated)
{
Context.User = UserPrincipal.Authenticate(Context.User.Identity as
System.Security.Principal.WindowsIdentity);
Thread.CurrentThread.Name = UserPrincipal.CurrentUser.LoginName;
}
else
{
throw new UnauthorizedAccessException("Windows Integrated Security is not enabled");
}
}
"
The above method is where i'm facing issue. In VS2019 the IsAuthenticated is returning false where it returned true in VS2012 and worked fine.
|
|
|
|
|
Then you either haven't enabled Windows Authentication, or you haven't disabled Anonymous Authentication.
Check your settings in web.config - you should have both:
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
</system.web> and:
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<basicAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer> NB: You may need to "unlock" the authentication section to be able to configure it. In IIS Manager, it's under "Feature Delegation". If you're using IIS Express, you'll need to edit the applicationhost.config file in the .vs\config hidden folder.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I checked with this code with empty web Form to check if authentication is working .
I received this error ,even after configuring the applicationHost.config (handler = Allow).Could you please help with this
Error:
"HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information:
Module WindowsAuthenticationModule
Notification AuthenticateRequest
Handler PageHandlerFactory-Integrated-4.0
Error Code 0x80070021
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File \\?\C:\Users\rharishpr\source\repos\WebApplication3\web.config
Requested URL https://localhost:44386/WebForm1.aspx
Physical Path C:\Users\rharishpr\source\repos\WebApplication3\WebForm1.aspx
Logon Method Not yet determined
Logon User Not yet determined
Config Source:
18: <authentication>
19: <windowsauthentication enabled="true">
20: <basicauthentication enabled="true">
"
Method used to check Windows authentication part:
" protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Application code executed using ");
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name + " ");
Response.Write("Is User Authenticated: ");
Response.Write(User.Identity.IsAuthenticated.ToString() + " ");
Response.Write("Authentication Type, if Authenticated: ");
Response.Write(User.Identity.AuthenticationType + " ");
Response.Write("User Name, if Authenticated: ");
Response.Write(User.Identity.Name + " ");
}
"
Web.config:
"
<configuration>
<system.web>
<compilation debug="true" targetframework="4.7.2">
<httpruntime targetframework="4.7.2">
<authentication mode="Windows">
<authorization>
<deny users="?">
<system.webserver>
<security>
<authentication>
<windowsauthentication enabled="true">
<basicauthentication enabled="true">
<anonymousauthentication enabled="false">
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warninglevel="4" compileroptions="/langversion:default /nowarn:1659;1699;1701">
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warninglevel="4" compileroptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+">
"
modified 16-Jun-20 3:33am.
|
|
|
|
|
Quote: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
The error message is pretty clear that you haven't "unlocked" the authentication sections.
It looks like you're using IIS Express, so you'll have to edit the applicationhost.config file in the hidden .vs\Project_Name\config folder within your solution.
Open the file in a text editor and search for the following lines:
<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<section name="basicAuthentication" overrideModeDefault="Deny" />
<section name="windowsAuthentication" overrideModeDefault="Deny" /> On each line, change "Deny" to "Allow". Save the changes and try running your project again.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I had set that to Allow in C:\Windows\System32\inetsrv\Config\applicationHost.config
"
"
Still i'm getting the same Error(I'm using windows 10(FYI)).
|
|
|
|
|
You are using IIS Express. You need to edit the applicationHost.config file in your solution folder.
There's a hidden folder called .vs within your solution folder. Inside that will be a folder with the same name as your project. Within that will be a folder called config . The applicationHost.config file you need to edit is in there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks a lot. It worked.For the Authentication snippet which i tested.
But in my project the isAuthenticated is returning "false" ,i thought my project had the same as snippet code issue but here even after configuring everything showing error and authentication is failing. Should we add our name somewhere so that isAuthenticated returns "TRUE"
|
|
|
|
|
If Windows authentication is enabled, and anonymous authentication is disabled and anonymous users blocked, then unauthenticated requests shouldn't be able to reach your application. There must be something else going on.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
okay
Will there be any file related to "windows integrated security" to be enabled as Project specific like applicationHost.config
|
|
|
|
|
If you've unlocked it in applicationHost.config and enabled it in web.config - making sure to disable anonymous authentication as well - then it should just work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes did that. Yet Context.Request.IsAuthenticated is returning false even after the changes in applicationHost.config of the project
|
|
|
|
|
There there's something else going on that I can't see. I've done this dozens of times; with the changes to applicationHost.config and web.config , it just works.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
i'm trying to print to an epson esc/pos printer using vb.net.
trying opening the serial post (the name is correct, i can see it dubuging) the execution goes in exception whith the error "Il nome specificato non inizia con COM/com o non si risolve in una porta seriale valida.Nome parametro: portName ParamName=portName"
This is my configuration code:
ADRPort = New System.IO.Ports.SerialPort(GLOBAL_DisplayCOMTkt, _
19200, _
Parity.None, _
8, _
StopBits.One)
...
...
...
...
If (ADRPort.IsOpen) Then
ADRPort.Close()
End If
If Not ADRPort.IsOpen Then
ADRPort.PortName = GLOBAL_DisplayCOMTkt
ADRPort.DtrEnable = False
ADRPort.RtsEnable = False
ADRPort.BaudRate = 19200
ADRPort.DataBits = 8
ADRPort.Parity = Parity.None
ADRPort.StopBits = StopBits.One
ADRPort.Handshake = Handshake.None
ADRPort.ReadTimeout = 2000
ADRPort.Open()
End If
Thanks for any support you can supply....
Fabio
|
|
|
|
|
The error message is pretty explicit: "Invalid port name"
Quote: The specified name does not begin with COM / com or does not resolve to a valid serial port. Parameter name: portName ParamName = portName "
So use the debugger, and look at exactly what you are setting the PortName property to: GLOBAL_DisplayCOMTkt has a value, but we have no idea what it is - and we can't do that for you!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have code in my DAL that I want to call from the UI asynchronously in my WPF app. I think I have this right, but I'd like to get your opinion.
DAL Interface
public interface IDAL
{
Task<List<ReportData>> GetReportData(ReportArgsEntity args);
}
DAL
public class MyDAL : IDAL
{
public Task<List<ReportData>> GetReportData(ReportArgsEntity args)
{
var t = Task.Factory.StartNew(() =>
{
List<ReportData> results = new List<ReportData>();
return results;
});
return t;
}
}
BL Interface
public interface IBL
{
Task<List<ReportData>> GetReportData(ReportArgsEntity args);
}
BL
public class MyBL : IBL
{
IDAL _dal;
public MyBL()
{
_dal = new MyDAL();
}
public Task<List<ReportData>> GetReportData(ReportArgsEntity args)
{
return _dal.GetReportData(args);
}
}
View Model
public class MyViewModel
{
IBL _bizLayer;
public MyViewModel()
{
_bizLayer = new MyBL();
}
private async void RunReport()
{
var args = new ReportArgsEntity()
{
};
var reportData = await _bizLayer.GetReportData(args);
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Richard Deeming wrote: First of all, you should really be using Task.Run instead:
I thought Task.Run and Task.Factory.StartNew do basically the same thing?
I'm using Linq To SQL
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
As Stephen said in the blog post, Task.Run is equivalent to:
Task.Factory.StartNew(someAction, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
It is possible to get proper async support in LINQ to SQL, although it's not perfect. For example:
public static async Task<List<T>> ToListAsync(this IQueryable<T> query, DbContext context, CancellationToken cancellationToken = default)
{
if (query is null) throw new ArgumentNullException(nameof(query));
if (context is null) throw new ArgumentNullException(nameof(context));
using (var command = (SqlCommand)context.GetCommand(query))
{
await command.Connection.OpenAsync(cancellationToken);
using (var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection, cancellationToken))
{
return _context.Translate<T>(reader).ToList();
}
}
} DataContext.GetCommand(IQueryable) Method (System.Data.Linq) | Microsoft Docs[^]
DataContext.Translate Method (System.Data.Linq) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: using (var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection, cancellationToken))
{
return _context.Translate<T>(reader).ToList();
}
OK, so I'm using Linq to SQL. What more can I do to make the method async? The Command has the ExecuteReaderAsync method, but my Linq to SQL code won't have any of that. For example:
public Task<List<ReportData>> GetReportData(ReportArgsEntity args)
{
var t = Task.Run(() =>
{
var results = new List<ReportData>();
using (var dc = GetDataContecxt())
{
results = (from c in dc.Companies
join ih in dc.InvoiceHeaders on c.Id equals ih.CustomerId
join id in dc.InvoiceDetails on ih.Id equals id.HeaderId
where c.Completed
select new ReportData
{
}).ToList();
}
return results;
});
return t;
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Use the extension method from my previous post. For example:
public async Task<List<ReportData>> GetReportData(ReportArgsEntity args)
{
await Task.Yield().ConfigureAwait(false);
var query = from c in dc.Companies
join ih in dc.InvoiceHeaders on c.Id equals ih.CustomerId
join id in dc.InvoiceDetails on ih.Id equals id.HeaderId
where c.Completed
select new ReportData
{
};
return await query.ToListAsync(dc);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I see.
The whole reason I'm asking is that right now all of the code is on the UI thread. But we're going to be moving the BL & DAL to Controllers in an ASP.Net Web API. So the UI will need to fire & forget each call and await the results.
Given that, and other that what we've already discussed, any reason this wouldn't work?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The Web API action can be async , so this code will just work as-is. You might want to drop the Task.Yield line though, since you're not worried about blocking the UI thread.
The client code can make async requests to the web API - how easy that is will depend on which library you're using to call it. Using async and await will ensure that the UI thread isn't blocked whilst you're waiting for a response from the network.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|