Reputation: 4992
This is a random thought I just had while playing around with a simple send email feature on my ASP.net website:
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("[email protected]");
mailMessage.From = new MailAddress("[email protected]");
System.Net.NetworkCredential basicauthenticationinfo = new
System.Net.NetworkCredential("username", "pass123");
The above is the extract of my code that got me thinking. After deploying the site, 'View Source' allowed me to view the HTML of my site, but I couldn't find any way to see the C# coding there in the ASPX.CS file behind it. I tried using FireBug too, and no luck. So is it safe to say that anyone viewing my website won't have any way to see the above information?
I have seen other examples of the above code where people usually specify the NetworkCredentials in the Web.Config file. Does this have the benefit of being any safer?
Is the main idea to try and make use of the Webconfig as much as possible in this scenario for the sake of security, or is this only for the sake of keeping the code 'tidier'?
Upvotes: 0
Views: 687
Reputation: 11607
The web.config
file is a better place, benefits being:
*.config
files are treated by ASP.NET as specially protected files, they will never be served;By keeping configuration information hard coded you renounce to those benefits and make your life harder on the security side.
Upvotes: 1