How to specify guest access to C#/SQL internet site? - c#

I just created a website in ASP.NET and C# and am hosting it now at this URL below. This URL is working now:
http://96.0.101.66/Default.aspx
However, currently this website does not list the SQL tables, which should be on the left-hand side of this window in a gridview. I think this is because I disabled anonymous access from IIS6 Manager. (I'm using IIS6 Manager on an XP OS). I disabled this cause I also have SQL Server 2008 on same machine. Same machine for hosting website, developing VS 2008 C# code, and SS 2008 database.
However, I see this gridview when I Browse my IIS6 Manager. So this webpage is working on my computer, just not from the internet.
Which user should I configure to access this website and how? Like should I choose ASPNET account? They should be able to append data to existing Adventureworks tables. They choose which table to append from this URL above.
Also, do I need to upload any MDF files from Adventureworks? I don't think so cause they should be able to access the Adventureworks database on my computer, right?
I checked Event Viewer and am getting the following Failure Audit:
Login failed for user 'NT
AUTHORITY\NETWORK SERVICE'. Reason:
Failed to open the explicitly
specified database. [CLIENT: ]
I'm new to IIS and C#, so any help is much appreciated!

Oh dear; please remove that website immediately, it's returning all your pages as it's probably not configured to run IIS. I'd stop that site being public ASAP.

Related

Is There A Way To Access The UserID of Windows Authentication for SQL Server Express?

I am developing an internal web app using Blazor (WebAssembly) and SQL Server Express 15. The web app will only be accessed while within our network.
As I am extremely early in development, I currently host the Blazor app and the SQL server on my workstation; eventually the app and SQL server will reside on a more traditional server inside our firewall.
I'm using the default Windows Authentication for SQL Server. What I'd like to do is, via Blazor, access the Windows userid of whoever is interacting with the SQL server by virtue of accessing the web app. I could then use that information to (for example) show that user their weekly timesheet when they go to My Timesheet within the web app.
Is there a way to access the Windows userid that authenticated into SQL Server? Or am I misunderstanding things / off-base is some fashion? Or is there another way to get the Windows userid without interacting with SQL Server?
What I've Tried
I've tried System.Environment.UserName, but that returns "Browser". I've also tried System.Environment.UserDomainName, but that returns "localhost". I've also tried System.Security.Principal.WindowsIdentity.GetCurrent().Name and code based on ManagementObjectSearcher, but both throw an exception under WebAssembly, as WebAssembly is not Windows (even when running on a Windows server and/or a Windows browser-client).
From the other suggestions in this question, I was unable to find the right using statements or other syntax in Blazor for
Request.LogonUserIdentity.Name,
System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName,
User.Identity.Name,
System.Windows.Forms.SystemInformation.UserName, and
HttpContext.Current.User.Identity.Name.
check this tutorial from Medium:
https://vaibhavbhapkarblogs.medium.com/windows-authentication-authorization-in-blazor-application-144d23dd90be
should be the right starting point.
The part you need is inside the custom AuthenticationStateProvider you need to implement:
//Getting logged in windows user name
var user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Azure Web Deployment Database Connection Problems

I've created an application using the ASP.Net Entity Framework 6 Code First approach.
The app runs fine locally, using a local instance of a SQL Server database.
After creating an azure account and publishing the site to the Azure service, the site home page and login pages load just fine.
If I try to login or access the 'register' page, I get the following exception:
Cannot open server "app.co.za" requested by the login.  The login
failed.
app.co.za is not the real domain name, I have replaced the original.
The original domain is only related to the site because I've created my Azure account using my email from that domain.
When specifying the Azure database under the deployment profile in Visual Studio, I entered the connection string provided on the Azure Portal with my Azure portal login details (which is where I think the issue might be).
Since this is a login issue though, I'm not sure if I've entered the correct set of credentials? I've made sure that there are no errors in the password.
How can I know that I have used the correct credentials to log in with?
Thanks!
Azure SQL Databases are firewalled and only allow connections from whitelisted IP addresses. If you haven't already done so, please browse to your Azure SQL DB in the Azure Portal and click on the Overview tab. You'll then see a "Set Server Firewall" menu option on the Overview tab. Add your current IP address to the list.
You can verify that your IP is whitelisted by connecting to your Azure SQL DB via Sql Server Management Studio.

ASP.NET MVC - Getting username of the user using my application

I am new to ASP.NET MVC and creating a little application in my spare time at work.
This application has windows authentication and connects to one of our remote test databases, and the application does some simple select/update/insert queries with one of the tables on this database.
For one part of my application, when a user clicks 'process', I save that user's username in my model by doing:
job.User = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
And then write that to the database.
Everything run's fine when I run it locally through visual studio, it recognises my domain name/username and saves that to the database.
Once publishing to IIS, I ask one of my team members to connect to my computername/site and when they try to click that same 'Process', they get
"Login failed for user 'OURDOMAINNAME/MYCOMPUTERNAME$'. "
My application is using DefaultAppPool with Identity set as 'ApplicationPoolIdentity'.
My whole team has permissions to access this database and if only my application picked up their correct domain group/username then it would OK but the application is trying to connect as MY computer and not my actual windows logon.
Can anybody please advise?
Since you are using ApplicationPoolIdentity, did you allow that user in your MSSQL database?
User: IIS APPPool\DefaultAppPool

SSRS ReportViewer Control Credentials

I'm working on a recently created server that was built to house a migrated version of SSRS, from SSRS 05 to 08.
Previously, we had no issues with connectivity from the IIS server to the SSRS server via the report viewer control and we did not supply credentials at that time. Now, when we try to use the viewer we get back; "The request failed with HTTP status 401: Unauthorized."
Obviously that is a new issue that we have never had before even though we never used credentials in the first place. So that is my first question... The new server is sitting in the same "place" as the old one. IP, Domain, Subnet is the same. Users have been set up the same, and the SSRS configuration appears to be the same. What could be the difference that is causing the error?
Also, i've been doing some testing, and I realized that I can access that server and get the reports in that environment by pointing my dev environment running in visual studio 2008 to that server without using credentials. I'm assuming by not setting the report viewer objects serverreport.reportservercredentials to something and leaving that property as a null value that it is using something else? possibly my windows user credentials? to access the reporting server. (That would be my second question.)
And finally. I decided to bite the bullet and implement credentials on the report viewer. When i create the credentials for the local user on the ssrs server that was created for this purpose, and is also listed in the report manager as a browser, i get the request failed error. My third question is; Is there something that I'm not thinking of for this type of implementation?
Please let me know if there are any questions or things that i need to clarify with in my post.
I ended up going down a different route.
There were two issues... first. the application on the web server was running as a local user. And the old SSRS server was set up to accept anonymous users.
To remedy this, I had our net work guys create a new domain account. I then changed the app pool identity for the application to use that domain account, and gave it list and write permissions on the temp folder and added it to the correct groups in windows.
I then gave that domain user browse ability on the reporting server.
this worked for 2.0+ apps... now i just need to figgure out what folders the user needs access to for the 1.1 apps.
(ps... i also found that the domain user actually works when i pass credentials via the report viewer control in .net.)

Cannot connect to the Sharepoint Site from Visual Studio 2010

I'm new to Sharepoint. I'm trying to create a simple webpart using Visual Studio 2010 but when I try to validate my Sharepoint Server (both VS 2010 and Sharepoint are present in the same system) it says:
Cannot connect to the SharePoint site: http://wpnne76648:2010. Make sure that the Site URL is valid, that the SharePoint site is running on the local computer, and that the current user as the necessary permissions to access the site.
If I ignore this and click finish and then try to deploy the application it says:
Error occurred in deployment step 'Recycle IIS Application Pool': The local SharePoint server is not available. Check that the server is running and connected to the SharePoint farm.
Note: I can open my web application in the browser.
Ref: 2
This issue can be fixed by doing the following :-
Added myself as the administrator
Added myself to SharePoint Farm Admin Group
Provided DB Owner access to SharePoint Content DB
I've tried the below steps and it solved my issue. using Sharepoint Power Shell to grant my user the privileges to Content Databases.
Add-SPShellAdmin -UserName domain\username This will add permissions to the config database in SharePoint 2010
Get-SPContentDatabase -WebApplication This will return information on the content database for the desired web application
Add-SPShellAdmin -UserName domain\username -database This will add permissions to the content database for the desired web application
UPDATE
I've also found that SQL Server Agent(SHAREPOINT) Service was disables, enabling it solved my issue one more time.
Have you tried to create a new site collection and connecting to that one? Take into account that merely creating the web application isnt enough, the site collection needs to be there as well.
$db = Get-SPContentDatabase -WebApplication http://mycompany.corp/
Add-SPShellAdmin -UserName domainName\username -database $db.Id
OK, if you have a local SharePoint Farm, you may have to create an AAM pointing to the default URL.
For example, I created a Web App: http://portaldev10.jedi.local but VS defaulted to http://DEV2010 and nothing I could do could get it to resolve the DNS URL... so I created an Internal AAM and VS works.
Crazy... I know
Probably this step will help you.
I tried all the possible solutions with Active Directory, IIS Authentication and finally was able to fix the issue just by doing the below. Hope this will help you in similar kind of issue.
1.Do a IIS reset
2.Check if IIS is resetting.
3.If it is not, then disable UAC from control panel and IIS reset will work.
4.Go to Central Administration site
5.Navigate to the Manage Web Applications page
6.Click on the web application that hosts the site you are trying to deploy
7.Click the User Policy ribbon item.
8.Add your windows account to the list of users with the Full Control permission.
Good Luck

Categories

Resources